#!/bin/sh

read -p "请输入当前系统密码:" SYSPWD
clear
ShFilesPath=~/.kylin-wol.sh
TodesktopFilesPath=~/.config/autostart/wol.desktop
echo '${SYSPWD}'| sudo -S touch $ShFilesPath
sudo chmod 777 $ShFilesPath
echo "#!/bin/sh" > $ShFilesPath


WangKaName=$(ifconfig | grep 'enp' | awk -F ":" '{print $1}' | sed 's/,/\n\r/g')
#===============方法2, 待测试========================================================
#1.ubuntu----------已测试OK
#2.UOS桌面版--------
#3.UOS服务器--------
#4.银河麒麟 --------

WangKaName2=`cat /proc/net/dev | awk '{i++;if(i>2)print $1}' |sed 's/[:]*$//g'`
for WKMANE in ${WangKaName2[@]}
	do 
	echo "echo '$SYSPWD' | sudo -S ethtool -s $WKMANE wol g" >> $ShFilesPath
	done
echo "#sudo ethtool $WangKaName" >> $ShFilesPath
echo "[Desktop Entry]" > $TodesktopFilesPath
echo "Name=银河麒麟-打开网络唤醒" >> $TodesktopFilesPath
echo "Exec=/home/kylin/.kylin-wol.sh %u" >> $TodesktopFilesPath
echo "Icon=/opt/InfreeClient/Infree.ico" >> $TodesktopFilesPath
echo "Type=Application" >> $TodesktopFilesPath
echo "Terminal=true" >> $TodesktopFilesPath
echo "StartupNotify=true" >> $TodesktopFilesPath
echo "Encoding=UTF-8" >> $TodesktopFilesPath
echo "Categories=Office;" >> $TodesktopFilesPath
sudo chmod 777 $TodesktopFilesPath
clear
echo "本窗口10秒后自动关闭,并将重启计算机..."
echo sudo ethtool $WangKaName
echo | sudo ethtool $WangKaName | grep 'Wake-on' | grep -v 'pumbg'
sleep 10
sudo reboot



exit 0
#=========================================================================================
ShFilesPath=~/.kylin-wol.sh
TodesktopFilesPath=~/.config/autostart/wol.desktop
echo '${SYSPWD}'| sudo -S touch $ShFilesPath
sudo chmod 777 $ShFilesPath
echo "#!/bin/sh" > $ShFilesPath
echo "echo '$SYSPWD' | sudo -S ethtool -s $WangKaName wol g" >> $ShFilesPath
echo "#sudo ethtool $WangKaName" >> $ShFilesPath
echo "[Desktop Entry]" > $TodesktopFilesPath
echo "Name=银河麒麟-打开网络唤醒" >> $TodesktopFilesPath
echo "Exec=/home/kylin/.kylin-wol.sh %u" >> $TodesktopFilesPath
echo "Icon=/opt/InfreeClient/Infree.ico" >> $TodesktopFilesPath
echo "Type=Application" >> $TodesktopFilesPath
echo "Terminal=true" >> $TodesktopFilesPath
echo "StartupNotify=true" >> $TodesktopFilesPath
echo "Encoding=UTF-8" >> $TodesktopFilesPath
echo "Categories=Office;" >> $TodesktopFilesPath
sudo chmod 777 $TodesktopFilesPath
clear
echo "本窗口10秒后自动关闭,并将重启计算机..."
echo sudo ethtool $WangKaName
echo | sudo ethtool $WangKaName | grep 'Wake-on' | grep -v 'pumbg'
sleep 10
sudo reboot
